package com.xzz.finger;

/**
 * @author: hhz
 * @create: 2022-02-15 13:46
 * 剑指 Offer 03. 数组中重复的数字
 **/
public class FindRepeatNumber {
    public static void main(String[] args) {
        System.out.println(findRepeatNumber(new int[]{2,3,1,0,2,5,3}));
    }
    public static int findRepeatNumber(int[] nums) {
        int i = 0;
        while (i<nums.length){
            if(nums[i]==i){
                i++;
                continue;
            }
            if(nums[nums[i]]==nums[i]){
                return nums[i];
            }
            int temp = nums[i];
            nums[i]= nums[temp];
            nums[temp] = temp;
        }
        return -1;
    }
}
